package com.aqie.easy.array;

import java.util.Arrays;

/**
 * 1051. 高度检查器
 * 排序算法
 */
public class HeightChecker {
    public int heightChecker(int[] heights) {
        int length = heights.length;
        int diff = 0;
        // 1. 数组复制
        int[] sortArr = Arrays.copyOf(heights, length);

        // 2. 数组排序
        Arrays.sort(sortArr);

        // 3. 对比差异
        for(int i = 0; i < length; i++){
            if (heights[i] != sortArr[i]){
                diff++;
            }
        }
        return diff;
    }

    public static void main(String[] args) {
        int [] nums = {1,1,4,2,1,3};
    }
}
